package com.demon.framework.boot.autoconfigure.app;


import com.demon.framework.util.gen.SnowflakeIdWorker;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 分布式Id生成算法
 *
 * @author Demon-HY
 * @date 2020-7-23
 */
@Configuration
public class IdWorkerAutoConfiguration {

    /**
     * 工作id,每个服务可以单独指定,不指定默认都为1
     */
    @Value("${demon.idWorker.workerId:1}")
    private long workerId;

    /**
     * 基于雪花算法实现分布式id
     *
     * @return
     */
    @Bean
    public SnowflakeIdWorker snowflakeIdWorker() {
        return new SnowflakeIdWorker(workerId);
    }
}
